package com.atguigu.common.exception;

import com.atguigu.common.result.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

@Slf4j
public class Assert {
    public static void notNull(Object obj, ResponseEnum responseEnum) {
        if (obj == null) {
            log.error("obj is null!!!");
            throw new BusinessException(responseEnum);
        }
    }

    public static void isNull(Object obj, ResponseEnum responseEnum) {
        if (obj != null) {
            log.error("obj is not null!!!");
            throw new BusinessException(responseEnum);
        }
    }

    public static void isTrue(boolean obj, ResponseEnum responseEnum) {
        if (!obj) {
            log.error("obj is not true!!!");
            throw new BusinessException(responseEnum);
        }
    }

    public static void equals(Object obj1, Object obj2, ResponseEnum responseEnum) {
        if (!obj1.equals(obj2)) {
            log.error("obj1 is not equal obj2!!!");
            throw new BusinessException(responseEnum);
        }
    }

    public static void notEquals(Object obj1, Object obj2, ResponseEnum responseEnum) {
        if (obj1.equals(obj2)) {
            log.error("obj1 is equal obj2!!!");
            throw new BusinessException(responseEnum);
        }
    }

    public static void notEmpty(String str, ResponseEnum responseEnum) {
        if (StringUtils.isEmpty(str)) {
            log.error("obj is null!!!");
            throw new BusinessException(responseEnum);
        }
    }
}
